<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>MouseClick</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>MouseClick</h1>

<p>Clicks or holds down a mouse button, or turns the mouse wheel. NOTE: The <a href="Click.htm">Click command</a> is generally more flexible and easier to use.</p>

<pre class="Syntax">MouseClick [, WhichButton , X, Y, ClickCount, Speed, D|U, R]</pre>
<h3>Parameters</h3>
<dl>

  <dt>WhichButton</dt>
  <dd><p><u>The button to click</u>: Left (default), Right, Middle (or just the first letter of each of these); or the fourth or fifth mouse button (X1 or X2). For example: <code>MouseClick, X1</code>. This parameter may be omitted, in which case it defaults to Left.</p>
      <p><u>Rotate the mouse wheel</u>: Specify WheelUp or WU to turn the wheel upward (away from you); specify WheelDown or WD to turn the wheel downward (toward you). In v1.0.48+, specify WheelLeft (or WL) or WheelRight (or WR) to push the wheel left or right, respectively (but these have no effect on operating systems older than Windows Vista). <em>ClickCount</em> is the number of notches to turn the wheel.</p>
      <p>To compensate automatically for cases where the user has swapped the left and right mouse buttons via the system's control panel, use the <a href="Click.htm">Click command</a> instead.</p></dd>

  <dt>X, Y</dt>
  <dd><p>The x/y coordinates to which the mouse cursor is moved prior to clicking, which can be <a href="../Variables.htm#Expressions">expressions</a>. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that. If omitted, the cursor's current position is used.</p></dd>

  <dt>ClickCount</dt>
  <dd><p>The number of times to click the mouse, which can be an <a href="../Variables.htm#Expressions">expression</a>. If omitted, the button is clicked once.</p></dd>

  <dt>Speed</dt>
  <dd><p>The speed to move the mouse in the range 0 (fastest) to 100 (slowest), which can be an <a href="../Variables.htm#Expressions">expression</a>. Note: a speed of 0 will move the mouse instantly. If omitted, the default speed (as set by <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> or 2 otherwise) will be used.</p>
      <p><em>Speed</em> is ignored for <a href="SendMode.htm">SendInput/Play modes</a>; they move the mouse instantaneously (though <a href="SetMouseDelay.htm">SetMouseDelay</a> has a mode that applies to SendPlay). To visually move the mouse more slowly -- such as a script that performs a demonstration for an audience -- use <code><a href="Send.htm#Click">SendEvent {Click 100, 200}</a></code> or <code><a href="SendMode.htm">SendMode Event</a></code> (optionally in conjuction with <a href="BlockInput.htm">BlockInput</a>).</p></dd>

  <dt>D|U</dt>
  <dd><p>If this parameter is omitted, each click will consist of a &quot;down&quot; event followed by an &quot;up&quot; event. Alternatively:<br>
      D = Press the mouse button down but do not release it (i.e. generate a down-event). <br>
      U = Release the mouse button (i.e. generate an up-event).</p></dd>

  <dt>R</dt>
  <dd><p>If this parameter is the letter R, the X and Y coordinates will be treated as offsets from the current mouse position. In other words, the cursor will be moved from its current position by X pixels to the right (left if negative) and Y pixels down (up if negative).</p></dd>

</dl>

<h3>Remarks</h3>
<p>This command uses the sending method set by <a href="SendMode.htm">SendMode</a>.</p>
<p>The <a href="Click.htm">Click command</a> is recommended over MouseClick because:</p>
<ol>
  <li>It automatically compensates when the left and right mouse buttons are swapped via the control panel.</li>
  <li>It is generally easier to use.</li>
</ol>
<p>To perform a shift-click or control-click, use the <a href="Send.htm">Send</a> command before and after the operation as shown in these examples:</p>
<pre><em>; Example #1: </em>
Send, {Control down}
MouseClick, left, 55, 233
Send, {Control up}</pre>
<pre>
<em>; Example #2:</em>
Send, {Shift down}
MouseClick, left, 55, 233
Send, {Shift up}</pre>
<p>The <a href="SendMode.htm">SendPlay mode</a> is able to successfully generate mouse events in a broader variety of games than the other modes. In addition, some applications and games may have trouble tracking the mouse if it moves too quickly. The <em>speed</em> parameter or <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> can be used to reduce the speed (in the default <a href="SendMode.htm">SendEvent mode</a> only).</p>
<p>Some applications do not obey a <em>ClickCount</em> higher than 1 for the mouse wheel. For them, use a <a href="Loop.htm">Loop</a> such as the following:</p>
<pre>Loop, 5
    MouseClick, WheelUp</pre>
<p>The <a href="BlockInput.htm">BlockInput</a> command can be used to prevent any physical mouse activity by the user from disrupting the simulated mouse events produced by the mouse commands. However, this is generally not needed for the <a href="SendMode.htm">SendInput/Play</a> modes because they automatically postpone the user's physical mouse activity until afterward.</p>
<p>There is an automatic delay after every click-down and click-up of the mouse (except for <a href="SendMode.htm">SendInput mode</a> and for turning the mouse wheel). Use <a href="SetMouseDelay.htm">SetMouseDelay</a> to change the length of the delay.</p>
<h3>Related</h3>
<p><a href="CoordMode.htm">CoordMode</a>, <a href="SendMode.htm">SendMode</a>, <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>, <a href="SetMouseDelay.htm">SetMouseDelay</a>, <a href="Click.htm">Click</a>, <a href="MouseClickDrag.htm">MouseClickDrag</a>, <a href="MouseGetPos.htm">MouseGetPos</a>, 
  <a href="MouseMove.htm">MouseMove</a>, <a href="ControlClick.htm">ControlClick</a>, <a href="BlockInput.htm">BlockInput</a></p>
<h3>Examples</h3>
<pre class="NoIndent"><em>; Double click at the current mouse pos:</em>
MouseClick, left
MouseClick, left

<em>; Same as above:</em>
MouseClick, left, , , 2

<em>; Move to specified coordinates then right-click once:</em>
MouseClick, right, 200, 300

<em>; Here are two hotkeys that simulate the turning of the mouse wheel:</em>
#up::MouseClick, WheelUp, , , 2  <em>; Turn it by two notches.</em>
#down::MouseClick, WheelDown, , , 2</pre>

</body>
</html>
